import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase="DBshop026_商品咨询删除"

import pymysql
#2.创建一个数据库连接
connection = pymysql.connect(host="localhost",user="root",password="root",database="dbshop",charset="utf8")
#3.创建一个游标用于执行SQL语句
cursor=connection.cursor()
#4.执行SQL语句
cursor.execute("DELETE FROM dbshop.dbshop_goods_ask;")
cursor.execute("commit;")
#5.断开数据库连接
connection.close()

firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)

element=firefox.find_element_by_partial_link_text("小米（MI）电视")
y=element.location["y"]     # 获取到元素的纵坐标
firefox.execute_script("window.scrollTo(0,%s)"%(y))
element.click()

e=firefox.find_element_by_id("goods_ask_content")
y=e.location["y"]
firefox.execute_script("window.scrollTo(0,%s)"%(y))
e.send_keys("这个有优惠吗？")
firefox.find_element_by_xpath("//button[text()='提交咨询']").click()
time.sleep(2)
firefox.find_element_by_xpath("//button[text()='提交咨询']").click()

firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"商品管理","商品咨询")

firefox.find_element_by_link_text("删除").click()
firefox.switch_to_alert().accept()

time.sleep(5)

s=firefox.find_element_by_xpath("//strong").text
l="咨询数："
r="\)"
num=reGetString(s,l,r)
print(num)


if num==0:
    writeLog("%s 测试通过" % (testCase))
else:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(firefox)